home *** CD-ROM | disk | FTP | other *** search
- /*
- AddEvent Macro
- Adds events to calendars created by my
- Calendar Macro for FinalWriter4+ (SoftWood)
- Written by Ronald Goertz
- $VER: AddEvent v2.40 (26 Sep 98)
- */
-
- OPTIONS RESULTS
- Address FINALW.1
-
- call addlib("rexxreqtools.library", 0, -30, 0)
- call addlib("rexxsupport.library", 0, -30, 0)
-
- call SetVariables
-
- TextBlockTypePrefs SIZE HighlightFSize WIDTH HighlightFWidth COLOR BlackName FONT DateFont
- BoxPrefs LINEWT Hairline FILL Solid FILLCOLOR WhiteName
-
- Month = substr(TempDate,5,2)
- if left(Month,1) == "0" then Month = right(Month,1)
- PrevMonth = Month - 1
- if PrevMonth = 0 then PrevMonth = 12
- NextMonth = Month + 1
- if NextMonth = 13 then NextMonth = 1
-
- Year = left(TempDate,4)
- if (Year//4 == 0 & Year//100 > 0) | Year//400 == 0 Then MonthLength.2 = 29
-
- interpret "StartDate = Day."Date('W', TempDate, 'S')
-
- if ~exists('t:'TempDate'.gc') then call BuildRequestor
-
- Do While 1
- Day1 = ''; Day2 = ''; EnteredLine = 1; Options = ''; EnteredEvent = ''; Box = 0; Weekly = 0
- call openport(TempDate)
- address command "gui t:"TempDate".gc"
- call WaitPkt(TempDate)
- packet = GetPkt(TempDate)
- call Reply(packet,0)
- call closeport(TempDate)
- call open(InData, 'env:EventData')
- input = ReadLn(InData)
- call close(InData)
- if input = "0" then do
- if upper(DecimalFormat) = 'COMMA' then DocItemPrefs Decimal Comma
- exit
- end
- Parse Var input Day1 ',' Day2 ',' EnteredLine ',' Options ',' EnteredEvent
-
- Day1 = strip(Day1)
- if Day1 = '' then do
- call rtezrequest('No day provided.')
- iterate
- end
- Day2 = strip(Day2)
- EnteredLine = strip(EnteredLine)
-
- Options = strip(Options)
- EnteredEvent = strip(EnteredEvent)
- do while pos(DollarSub, EnteredEvent) > 0
- posn = pos(DollarSub, EnteredEvent)
- EnteredEvent = OVERLAY('$', EnteredEvent, posn)
- end
-
- Options = compress(upper(Options))
- if pos('B', Options) ~= 0 | pos('//',Event) ~= 0 then Box = 1
- if pos('W', Options) ~= 0 then Weekly = 1
- If Day2 == "" then Day2 = Day1
-
- do until Weekly = 0
- Event = EnteredEvent
- Line = EnteredLine
-
- If upper(left(Day1,1)) == "P" then Day1 = substr(Day1,2) - MonthLength.PrevMonth
- If upper(left(Day2,1)) == "P" then Day2 = substr(Day2,2) - MonthLength.PrevMonth
- If upper(left(Day1,1)) == "N" then Day1 = substr(Day1,2) + MonthLength.Month
- If upper(left(Day2,1)) == "N" then Day2 = substr(Day2,2) + MonthLength.Month
-
- If Day1 > Day2 then Do
- TempDate = Day1
- Day1 = Day2
- Day2 = TempDate
- End
- If Day1 ~= Day2 then Box = 1
-
- If Day1 <= -StartDate then Do
- ShowMessage 1 0 '"Dates cannot come before" "the beginning of the calendar." "" "OK" "" ""'
- if upper(DecimalFormat) = 'COMMA' then DocItemPrefs Decimal Comma
- Exit
- End
-
- if ((StartDate + MonthLength.Month > 35) & (Day2 > MonthLength.Month)) | ((StartDate + MonthLength.Month < 36) & (Day2 > 35 - StartDate)) then do
- ShowMessage 1 0 '"Dates cannot come after" "the end of the calendar." "" "OK" "" ""'
- if upper(DecimalFormat) = 'COMMA' then DocItemPrefs Decimal Comma
- Exit
- End
-
- Day1Row = trunc((Day1 + StartDate - 1)/7)
- Day2Row = trunc((Day2 + StartDate - 1)/7)
- Day1Column = (Day1 + StartDate) - 7*Day1Row - 1
- LeftEdge = LeftMargin + Day1Column*BoxWidth + TextOffset
- If Day1Row < 5 then PrintRow = Day1Row * BoxHeight
- else PrintRow = trunc(4.5 * BoxHeight)
-
- If Box == 0 then do /* Single day, unboxed event */
- Textline = 1
- event2 = ''
- Do until event == ''
- TextBottom = TopMargin + TextArea + PrintRow + (Line+1)*FHeight*1.1
- TextLeft = LeftMargin + Day1Column*BoxWidth + TextOffset*Textline
- DrawTextBlock 1 TextLeft TextBottom Event; obj = result
- redraw
- GetObjectCoords obj; coords = result
- parse var coords Pg . . TextWidth .
- If length(event) > 34 then TextWidth = 2*BoxWidth
- if (TextWidth + Textline*TextOffset >= BoxWidth) & (Words(event) > 1) then do
- posn = lastpos(' ', event)
- event2 = strip(substr(event, posn)' 'event2)
- event = strip(left(event, posn))
- DeleteObject obj
- end
- else if event2 ~= '' then do
- Textline = 3
- Line = Line + 1
- event = event2
- event2 = ''
- end
- else event = ''
- End
- end
- else do until Day1Row > Day2Row /* boxed events*/
- SearchPos = 1
- Found = 1
- TextRows = 1
- do until Found = 0
- Found = pos('//',Event,SearchPos)
- if Found > 0 then do
- Text.TextRows = substr(Event,SearchPos,Found - SearchPos)
- SearchPos = Found + 2
- TextRows = TextRows + 1
- end
- else Text.TextRows = substr(Event,SearchPos)
- end
-
- if Day2Row > Day1Row then CurrentWidth = (LeftMargin + 7*BoxWidth) - LeftEdge
- else Do
- Day2Column = (Day2 + StartDate) - 7*Day2Row - 1
- CurrentWidth = (LeftMargin + (Day2Column + 1)*BoxWidth - TextOffset) - LeftEdge
- End
-
- /* The only number in the following line may need to be adjusted (larger for smaller fonts,
- smaller for larger fonts) */
- TopEdge = TopMargin + TextArea + PrintRow + Line*FHeight*1.1 + (FHeight * .3)
- DrawBox 1 LeftEdge TopEdge CurrentWidth FHeight*TextRows*1.1
-
- do i = 1 to TextRows
- TextBottom = TopMargin + TextArea + PrintRow + (Line+i)*FHeight*1.1
- DrawTextBlock 1 1 TextBottom Text.i
- ID = RESULT
- GetObjectCoords ID
- parse var result . . . TextWidth TextHeight
- TextLeft = LeftEdge + (CurrentWidth - TextWidth)/2
- SetObjectCoords ID 1 TextLeft TextBottom TextWidth TextHeight
- end
-
- Day1Row = Day1Row + 1
- If Day1Row < 5 then PrintRow = Day1Row * BoxHeight
- else PrintRow = trunc(4.5 * BoxHeight)
- LeftEdge = LeftMargin
- End
- if Weekly == 1 then do
- Day1 = Day1 + 7
- Day2 = Day2 + 7
- if ((StartDate + MonthLength.Month > 35) & (Day2 > MonthLength.Month)) | ((StartDate + MonthLength.Month < 36) & (Day2 > 35 - StartDate)) then Weekly = 0
- if ((StartDate + MonthLength.Month > 35) & (Day1 > MonthLength.Month)) | ((StartDate + MonthLength.Month < 36) & (Day1 > 35 - StartDate)) then Weekly = 0
- end
- end
- Redraw
- SelectObject
- End
-
- /******* BuildRequestor Subroutine ***********/
- BuildRequestor: Procedure expose PrevMonth Month NextMonth Month. MonthLength. TempDate StartDate LF Day.
-
- Left = 5
- Top = 40
- RWidth = 17
- Height = 12
- PMonth = left(Month.PrevMonth, 3)
- CMonth = left(Month.Month, 3)
- NMonth = left(Month.NextMonth, 3)
-
- call open(Req, 't:'TempDate'.gc', W)
- Text = 'G4C'LF'WINBIG 261 180 230 130 "Enter event information:"'LF'WinType 11110000'LF'xOnLoad'LF
- Text = Text'GuiOpen 'TempDate'.gc'LF'StartEnd = 1'LF'Line = 1'LF'PMonth = "'PMonth'"'LF
- Text = Text'Month = "'CMonth'"'LF'NMonth = "'NMonth'"'LF'StartTxt = "Start: "'LF'EndTxt = " End: "'LF
- Text = Text'..EventData = "0"'LF'AppName = "'TempDate'.gc"'LF'xOnClose'LF'SENDREXX "'TempDate'" "Done"'LF'GuiQuit $AppName'LF
- Text = Text'XTEXTIN 50 5 175 15 "Event:" Event "" 100'LF'TEXT 140 25 100 12 "Start:" 13 nobox'LF
- Text = Text'GadID 1'LF'TEXT 140 40 100 12 " End:" 13 nobox'LF'GadID 2'LF'XCYCLER 184 55 35 11 "Line:" Line'LF
- Text = Text'CSTR 1 1'LF'CSTR 2 2'LF'CSTR 3 3'LF'CSTR 4 4'LF'CSTR 5 5'LF'CSTR 6 6'LF'CSTR 7 7'LF'CSTR 8 8'LF'CSTR 9 9'LF
- Text = Text'XCHECKBOX 184 70 26 11 " Boxed:" "Box" "B" "" OFF'LF'XCHECKBOX 184 85 26 11 "Weekly:" "Weekly" "W" "" OFF'LF
- Text = Text'XBUTTON 133 100 45 14 " _OK "'LF'Options = $Box'LF'AppVar Options $Weekly'LF
- Text = Text'..EventData = "$StartDate\, $EndDate\, $Line\, $Options\, $Event\n"'LF
- Text = Text'Quit'LF'XBUTTON 180 100 45 14 "_Cancel"'LF'QUIT'LF
- Text = Text'TEXT 5 25 119 12 "'Month.Month'" 9 BOX'LF'GadTXT CENTER'LF'Text 11 38 8 12 "'left(Day.0,1)'" 1 nobox'LF
- Text = Text'Text 28 38 8 12 "'left(Day.1,1)'" 1 nobox'LF'Text 45 38 8 12 "'left(Day.2,1)'" 1 nobox'LF'Text 62 38 8 12 "'left(Day.3,1)'" 1 nobox'LF
- Text = Text'Text 79 38 8 12 "'left(Day.4,1)'" 1 nobox'LF'Text 96 38 8 12 "'left(Day.5,1)'" 1 nobox'LF'Text 113 38 8 12 "'left(Day.6,1)'" 1 nobox'LF
-
- i = 0
- Day = 0
- PrevDay = MonthLength.PrevMonth - StartDate
- NextDay = 0
- Do while (i < 6)
- j = 0
- Do while (j < 7)
- SerialPosition = (i * 7) + j
- if (SerialPosition >= StartDate) & (SerialPosition < StartDate + MonthLength.Month) then Do
- Day = Day + 1
- Text = Text'XBUTTON 'Left + j*RWidth' 'Top + 10 + i*Height' 'RWidth' 'Height' "'Day'"'LF
- Text = Text'GOSUB $AppName SetDate "'CMonth' 'Day'" ""'LF
- End
- else Do
- if SerialPosition < StartDate then Do
- PrevDay = PrevDay + 1
- Text = Text'XBUTTON 'Left + j*RWidth' 'Top + 10 + i*Height' 'RWidth' 'Height' "'PrevDay'"'LF
- Text = Text'GOSUB $AppName SetDate "'PMonth' 'PrevDay'" "P"'LF
- End
- else Do
- NextDay = NextDay + 1
- Text = Text'XBUTTON 'Left + j*RWidth' 'Top + 10 + i*Height' 'RWidth' 'Height' "'NextDay'"'LF
- Text = Text'GOSUB $AppName SetDate "'NMonth' 'NextDay'" "N"'LF
- End
- End
- j = j + 1
- End
- i = i + 1
- if SerialPosition >= StartDate + MonthLength.Month - 1 then leave
- End
-
- Text = Text'xRoutine SetDate Date Month'LF'StartEnd == 1 - $StartEnd'LF'SE == $StartEnd + 1'LF
- Text = Text'if $SE = 1'LF'Val = $StartTxt'LF'StartDate = $Month'LF'AppVar StartDate $Date[-2][2]'LF
- Text = Text'else'LF'Val = $EndTxt'LF'EndDate = $Month'LF'AppVar EndDate $Date[-2][2]'LF'endif'LF
- Text = Text'AppVar Val $Date'LF'update $AppName $SE $Val'LF'return'
- call WriteLn(Req, Text)
- call close(Req)
-
- return
-
- /******* CalculateDate Subroutine ***********/
- CalculateDate:
- /* Month is the month in which the highlight occurs */
- /* HighDate is the highest (numerical) date on which the highlight will occur */
- /* HighDay is the weekday on which HighDate will occur */
- /* Event is the highlight text */
- parse arg GD_Month, GD_HighDay, GD_HighDate, GD_Event
-
- interpret 'GD_HighDay = Day.'GD_HighDay
- interpret 'GD_First = Day.'Date(W, Year''right(GD_Month, 2, '0')'01', S)
-
- GD_Day = GD_HighDate + (GD_HighDay - GD_First)
- if GD_First < GD_HighDay then GD_Day = GD_Day - 7
- Highlight.GD_Month.GD_Day = GD_Event
- return 0
-
- /******* SetVariables Subroutine ***********/
- SetVariables:
- DateFont = "SoftSans"
- HighlightFSize = 8
- HighlightFWidth = 100
- DollarSub = 'ยข'
-
- Day.Sunday = 0
- Day.Monday = 1
- Day.Tuesday = 2
- Day.Wednesday = 3
- Day.Thursday = 4
- Day.Friday = 5
- Day.Saturday = 6
-
- Day.0 = 'Sunday'
- Day.1 = 'Monday'
- Day.2 = 'Tuesday'
- Day.3 = 'Wednesday'
- Day.4 = 'Thursday'
- Day.5 = 'Friday'
- Day.6 = 'Saturday'
-
- Month.1 = 'January'
- Month.2 = 'February'
- Month.3 = 'March'
- Month.4 = 'April'
- Month.5 = 'May'
- Month.6 = 'June'
- Month.7 = 'July'
- Month.8 = 'August'
- Month.9 = 'September'
- Month.10 = 'October'
- Month.11 = 'November'
- Month.12 = 'December'
-
- MonthLength.1 = 31
- MonthLength.2 = 28
- MonthLength.3 = 31
- MonthLength.4 = 30
- MonthLength.5 = 31
- MonthLength.6 = 30
- MonthLength.7 = 31
- MonthLength.8 = 31
- MonthLength.9 = 30
- MonthLength.10 = 31
- MonthLength.11 = 30
- MonthLength.12 = 31
-
- if exists(Pragma(D)'/FWMacros/FWCalendar.data') then do
- call open(DataFile, Pragma(D)'/FWMacros/FWCalendar.data')
- do until eof(DataFile)
- Ln = ReadLn(DataFile)
- if left(Ln, 15) == '/* End Pass One' then leave
- interpret Ln
- end
- call close(DataFile)
- end
-
- LF = '0a'x
-
- GetDocItemPrefs Decimal; DecimalFormat = result
- DocItemPrefs Decimal Period
- GetPageSetup Width Height
- parse var result FullWidth FullHeight
-
- GetDisplayPrefs Measure; Units = result
- select
- when Units = 'Inches' then PointsPerUnit = 72
- when Units = 'Metric' then PointsPerUnit = 28.34645669291
- when Units = 'Pica' then PointsPerUnit = 12
- end
-
- FHeight = HighlightFSize / PointsPerUnit
- TextOffset = 3.6 / PointsPerUnit
-
- GetTextBlockText 2; TempDate = RESULT
- GetTextBlockText 3; Margins = result
- parse var Margins TopMargin'|'BottomMargin'|'LeftMargin'|'RightMargin'|'TextArea
- SelectObject
-
- PageWidth = FullWidth - LeftMargin - RightMargin
- PageHeight = FullHeight - TopMargin - BottomMargin
- BoxWidth = PageWidth/7
- if TextArea == '' then TextArea = .15 * PageHeight
- BoxHeight = (PageHeight-TextArea)/5
-